package core.java.test.bounce;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JPanel;

/**
 * 描述：
 *
 * @author liuchuang
 * @date 2022/1/6 11:21
 */
public class BallComponent extends JPanel {

    private static final int DEFALUT_WIDTH = 450;
    private static final int DEFALUT_HEIGHT = 350;

    private java.util.List<Ball> balls = new ArrayList<>();

    public void add(Ball ball) {
        balls.add(ball);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        for (Ball b : balls) {
            g2.fill(b.getShape());
        }
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(DEFALUT_WIDTH, DEFALUT_HEIGHT);
    }

}
